function e(e) {
    return e && e.__esModule ? e : {
        default: e
    };
}

var s = e(require("../../api/api.js")), t = e(require("../../utils/util.js")), a = e(require("../../utils/filter.js")), i = require("../../config/constants.js"), n = require("../../data/translate.js");

Page({
    data: {
        tabs: [ "当前服务", "历史服务" ],
        session_types: n.SESSION_VIEW_TYPES,
        package_types: n.PACKAGE_VIEW_TYPES,
        session_problem_types: n.SESSION_PROBLEM_VIEW_TYPES,
        session_type: "all",
        package_type: "all",
        session_problem_type: "problem_all",
        session_type_index: 0,
        package_type_index: 0,
        session_problem_type_index: 0,
        activeIndex: 0,
        sliderOffset: 0,
        sliderLeft: 0,
        sessionPageNum: 1,
        sessionListPageSize: 20
    },
    onShow: function() {
        this.onLoad();
    },
    onLoad: function() {
        wx.getStorageSync("userPersonalInfo") || wx.navigateTo({
            url: "../auth/auth"
        });
        var e = this;
        this.data.sessionPageNum = 1, 0 === this.data.activeIndex ? this.getSessionList() : 1 === this.data.activeIndex ? this.getSessionPackageList() : 2 === this.data.activeIndex && this.getSessionProblemList(), 
        wx.getSystemInfo({
            success: function(s) {
                e.setData({
                    sliderLeft: (s.windowWidth / e.data.tabs.length - 96) / 2,
                    sliderOffset: s.windowWidth / e.data.tabs.length * e.data.activeIndex
                });
            }
        });
    },
    getSessionList: function() {
        var e = this, t = this, a = wx.getStorageSync("token") || "", i = {
            page: this.data.sessionPageNum,
            type: this.data.session_type,
            i_token: a
        };
        s.default.sessionList({
            data: i,
            success: function(s) {
                if (s && s.data.data) {
                    var a = t.data.session_list;
                    1 === i.page && (a = []);
                    var n = s.data.data;
                    n.forEach(e.mergeSessionInfo);
                }
                void 0 !== n && n.length > 0 ? n.length < t.data.sessionListPageSize ? t.setData({
                    session_list: a.concat(n),
                    hasMore: !1
                }) : t.setData({
                    session_list: a.concat(n),
                    hasMore: !0,
                    sessionPageNum: t.data.sessionPageNum + 1
                }) : t.setData({
                    session_list: []
                });
            }
        });
    },
    onReachBottom: function(e) {
        0 === this.data.activeIndex && this.data.hasMore ? this.getSessionList() : 1 === this.data.activeIndex && this.data.hasMore ? this.getSessionPackageList() : 2 === this.data.activeIndex && this.data.hasMore && this.getSessionProblemList();
    },
    mergeSessionInfo: function(e) {
        e.course_title = a.default.sessionCourseTitle(e), e.session_start_hour = t.default.getSpecificHourByDate(e.session_start_time_user), 
        e.session_start_day = t.default.getSpecificDayByDate(e.session_start_time_user), 
        e.user_avatar_file = i.CDN_ADDR + e.oppo_user_obj.avatar_file_name + "_Avatar.jpg", 
        e.status_desc = a.default.convertSessionStatus(e), e.session_status_desc = a.default.convertSessionStatusDesc(e), 
        e.learn_language_cn = a.default.convertSymbolToText(e.learn_language, n.LANGUAGE_DATUM) || e.learn_language, 
        0 === e.package_id ? e.session_data_type = "session" : e.session_data_type = "package";
    },
    getSessionPackageList: function() {
        var e = this, t = this, a = wx.getStorageSync("token") || "", i = {
            page: this.data.sessionPageNum,
            type: this.data.package_type,
            i_token: a
        };
        s.default.sessionPackageList({
            data: i,
            success: function(s) {
                if (s && s.data.data) {
                    var a = t.data.session_package_list;
                    1 === i.page && (a = []);
                    var n = s.data.data;
                    n.forEach(e.mergePackageInfo), n.length > 0 ? n.length < t.data.sessionListPageSize ? t.setData({
                        session_package_list: a.concat(n),
                        hasMore: !1
                    }) : t.setData({
                        session_package_list: a.concat(n),
                        hasMore: !0,
                        sessionPageNum: t.data.sessionPageNum + 1
                    }) : t.setData({
                        session_package_list: []
                    });
                } else t.setData({
                    session_package_list: []
                });
            }
        });
    },
    mergePackageInfo: function(e) {
        e.course_title = a.default.sessionCourseTitle(e), "0" !== e.status && "3" !== e.status && "b" !== e.status && "6" !== e.status && "c" !== e.status && "5" !== e.status || (e.status_desc = "bg-theme"), 
        e.session_status_desc = a.default.convertPackageStatusDesc(e), e.user_avatar_file = i.CDN_ADDR + e.oppo_user_obj.avatar_file_name + "_Avatar.jpg", 
        e.learn_language_cn = a.default.convertSymbolToText(e.learn_language, n.LANGUAGE_DATUM) || e.learn_language;
    },
    getSessionProblemList: function() {
        var e = this, t = this, a = wx.getStorageSync("token") || "", i = {
            page: this.data.sessionPageNum,
            type: this.data.session_problem_type,
            i_token: a
        };
        s.default.sessionList({
            data: i,
            success: function(s) {
                if (s && s.data.data) {
                    var a = t.data.session_problem_list;
                    1 === i.page && (a = []);
                    var n = s.data.data;
                    n.forEach(e.mergeSessionProblemInfo), n.length > 0 ? n.length < t.data.sessionListPageSize ? t.setData({
                        session_problem_list: a.concat(n),
                        hasMore: !1
                    }) : t.setData({
                        session_problem_list: a.concat(n),
                        hasMore: !0,
                        sessionPageNum: t.data.sessionPageNum + 1
                    }) : e.setData({
                        session_problem_list: []
                    });
                } else e.setData({
                    session_problem_list: []
                });
            }
        });
    },
    mergeSessionProblemInfo: function(e) {
        e.course_title = a.default.sessionCourseTitle(e), e.session_start_hour = t.default.getSpecificHourByDate(e.session_start_time_user), 
        e.session_start_day = t.default.getSpecificDayByDate(e.session_start_time_user), 
        e.user_avatar_file = i.CDN_ADDR + e.oppo_user_obj.avatar_file_name + "_Avatar.jpg", 
        e.status_desc = a.default.convertSessionProblemStatus(e), e.session_status_desc = a.default.convertSessionProblemStatusDesc(e), 
        e.learn_language_cn = a.default.convertSymbolToText(e.learn_language, n.LANGUAGE_DATUM) || e.learn_language;
    },
    tabClick: function(e) {
        var s = Number(e.currentTarget.id);
        this.setData({
            sliderOffset: e.currentTarget.offsetLeft,
            activeIndex: s
        }), 0 !== s || this.data.session_list ? 1 !== s || this.data.session_package_list ? 2 !== s || this.data.session_problem_list || (this.data.sessionPageNum = 1, 
        this.getSessionProblemList()) : (this.data.sessionPageNum = 1, this.getSessionPackageList()) : (this.data.sessionPageNum = 1, 
        this.getSessionList());
    },
    bindToDetail: function(e) {
        var s = e.currentTarget.dataset.name;
        s.package_id ? wx.navigateTo({
            url: "../sessions/detail/detail?id=" + s.package_id + "&type=" + e.currentTarget.dataset.type
        }) : wx.navigateTo({
            url: "../sessions/detail/detail?id=" + s.session_id + "&type=" + e.currentTarget.dataset.type
        });
    },
    bindToSessionDetail: function(e) {
        var s = e.currentTarget.dataset.name;
        wx.navigateTo({
            url: "../sessions/detail/detail?id=" + s.session_id + "&type=" + e.currentTarget.dataset.type
        });
    },
    bindToPackageDetail: function(e) {
        var s = e.currentTarget.dataset.name;
        wx.navigateTo({
            url: "../sessions/detail/detail?id=" + s.id + "&type=" + e.currentTarget.dataset.type
        });
    },
    toggleSessionType: function(e) {
        var s = e.detail.value, t = this.data.session_types[s].v;
        this.setData({
            session_type: t,
            session_type_index: s
        }), this.data.sessionPageNum = 1, this.getSessionList();
    },
    togglePackageType: function(e) {
        var s = e.detail.value, t = this.data.package_types[s].v;
        this.setData({
            package_type: t,
            package_type_index: s
        }), this.data.sessionPageNum = 1, this.getSessionPackageList();
    },
    toggleSessionProblemType: function(e) {
        var s = e.detail.value, t = this.data.session_problem_types[s].v;
        this.setData({
            session_problem_type: t,
            session_problem_type_index: s
        }), this.data.sessionPageNum = 1, this.getSessionProblemList();
    },
    onImageError: function(e) {
        var s = this;
        t.default.errImgFun(e, s);
    },
    switchTab: function(e) {
        this.setData({
            currentNavtab: e.currentTarget.dataset.idx
        });
    }
});